#include "glut.h"
#include "ApplicationGL.h"
#include "defines.h"

CApplicationGL *g_ApplicationGL = NULL;

void glutIdle (void)
{
	// Display the frame
	glutPostRedisplay();
}

void glutDisplay (void)
{
	g_ApplicationGL->Update();
	g_ApplicationGL->Render();
}

void glutKeyboard (unsigned char key, int x, int y)
{
	switch (key)
	{
		case ESCAPE_KEY:
			{
				CHECKED_DELETE(g_ApplicationGL);
				exit (0);
				break;
			}
	}
}

int main(int argc, char* argv[])
{
	g_ApplicationGL = new CApplicationGL();
	if( g_ApplicationGL->Init() )
	{
		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
		glutInitWindowSize(GL_WIN_SIZE_X, GL_WIN_SIZE_Y);
		glutCreateWindow ("OpenNI Simple Viewer");
		//glutFullScreen();
		glutSetCursor(GLUT_CURSOR_NONE);

		glutKeyboardFunc(glutKeyboard);
		glutDisplayFunc(glutDisplay);
		glutIdleFunc(glutIdle);

		glDisable(GL_DEPTH_TEST);
		glEnable(GL_TEXTURE_2D);

		// Per frame code is in glutDisplay
		glutMainLoop();
	}

	return 0;
}